My first Quarto document

Intro

Macalester College is in the Twin Cities. It has:

  • four seasons
  • bagpipes
  • delightful students

Check it out for yourself:



Exercise 1: Deduce Quarto features

Check out the appearance and contents of this document. Thoughts?

In the toolbar at the top of this document, Render the .qmd file into a .html file. Where is this file stored? Thoughts about its appearance / contents? Can you edit it?

Toggling between the .qmd and .html files, explain the purpose of the following features in the .qmd file:

* = italicizes the text

** = bolds the text

# = makes the text a headline

- = differentiates the title and formatting code from the content of the website

\ = creates space

![](url) = inserts the image of the url




Exercise 2: Code

How does this appear in the .qmd? The .html? So…?!

seq(from = 100, to = 1000, by = 50)

It does not compute the answer; since it is outside of a code chunk, it is only registered as regular text.




Exercise 3: Chunks

Quarto isn’t a mind reader – we must distinguish R code from text. We do so by putting code inside an R chunk:

Code
seq(1,1,1)
[1] 1
  • Put the seq() code in the chunk.
  • Press the green arrow in the top right of the chunk. What happens in the qmd?
  • Render. What appears in the html: R code, output, or both? Answer: Both!




Exercise 4: Practice

  • Use R code to create the following sequence: 10 10 10 10
  • Store the sequence as four_tens.
  • Use an R function (which we haven’t learned!) to add up the numbers in four_tens.
Code
seq(from = 10, to = 10, length = 3)
[1] 10 10 10
Code
four_tens<-seq(from = 10, to = 10, length = 3)
sum(four_tens)
[1] 30




Exercise 5: Fix this code

Code is a form of communication, and the code below doesn’t cut it.

Put the code in a chunk and fix it.

Code
rep(x = 1, times = 10)
 [1] 1 1 1 1 1 1 1 1 1 1
Code
seq(from = 100, to = 1000, length = 20)
 [1]  100.0000  147.3684  194.7368  242.1053  289.4737  336.8421  384.2105
 [8]  431.5789  478.9474  526.3158  573.6842  621.0526  668.4211  715.7895
[15]  763.1579  810.5263  857.8947  905.2632  952.6316 1000.0000
Code
numberofStudents<-27




Exercise 6: Comments

Run the chunk below. Notice that R ignores anything in a line starting with a pound sign (#). If we took the # away we’d get an error!

Code
# This is a comment
4 + 5
[1] 9

We’ll utilize this feature to comment our code, i.e. leave short notes about what our code is doing. Below, replace the ??? with an approipriate comment.

Code
#Converting Celsius temperature to Fahrenheit. 
temperature_c <- 10
temperature_f <- temperature_c * 9/5 + 32
temperature_f
[1] 50